﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Office.Interop.Excel;

namespace ObjectModel.Excel
{
    /// <summary>
    /// A serializable class that holds a reference to an ObservableRange object. Assumes that
    /// the underlying range object will always be available for the duration of this object's life.
    /// </summary>
    public class ObservableCachedRange : CachedRange, IObservableSerializableRange
    {
        private ObservableRange mObservableRange;

        public ObservableCachedRange() : base() { } // Parameterless constructor required for serialization.

        public ObservableCachedRange(Range range) : base(new OfflineRangeOld(range)) { }

        [XmlIgnore]
        public IRangeEvents Events
        {
            get
            {
                if (mObservableRange == null)
                    mObservableRange = new ObservableRange(base.Range);
                
                return mObservableRange;
            }
        }

        public void Select()
        {
            mObservableRange.Select();
        }
    }
}
